// import _ from 'lodash';
import { message } from 'antd'
import { createReducer, clone } from '../util'
import types from '../store/types'

const InitState = {
  searchData:[],
  searchPsrsonData:{
    data:[],
    pageSize:10,
    totalPage:0,
    currentPage:1,
    totalRecord:0
  },
  taskDistribute:[],
  taskStatisData:{
    'allTaskNum': '0',
    'untreatedTaskNum': '0',
    'notTransmittedTaskNum': '0',
    'processingTaskNum': '0',
    'completedTaskNum': '0',
    'closedTaskNum': '0'
  },
  taskStatisDataChart:{
    'allTaskNum': '0',
    'untreatedTaskNum': '0',
    'notTransmittedTaskNum': '0',
    'processingTaskNum': '0',
    'completedTaskNum': '0',
    'closedTaskNum': '0'
  },
  dynamicList:{
    data:[],
    pageSize:3,
    totalPage:0,
    currentPage:1,
    totalRecord:0
  }
}

export default createReducer(InitState, {
  [`${types.GET_TASK_DISTRIBUTE}_SUCCESS`]: (state, data, params) => {
    	let state1 = clone(state)
    // loading=false;
    if(data.code == '0'){
        	state1.taskDistribute = data.content.taskDistributes
    }
    return state1
  },
  [`${types.GET_TASK_STATISDATA}_SUCCESS`]: (state, data, params) => {
    	let state1 = clone(state)
    // loading=false;
    if(data.code == '0'){
        if(params == 'all'){
            state1.taskStatisData = data.content.taskStatisticDatas[0];
        }else if(params == 'chart'){
            state1.taskStatisDataChart = data.content.taskStatisticDatas[0];
        }
    }
    return state1
  },
  [`${types.GET_TASK_DYNAMIC_LIST}_SUCCESS`]: (state, data, params) => {
    	let state1 = clone(state)
    // loading=false;
    if(data.code == '0'){
        	state1.dynamicList.data = data.content.taskDynamicLists
        	state1.dynamicList.pageSize = data.pageSize
        	state1.dynamicList.totalPage = data.totalPage
        	state1.dynamicList.currentPage = data.currentPage
        	state1.dynamicList.totalRecord = data.totalRecord
    }
    return state1
  },
  [`${types.GET_TASK_LIST}_SUCCESS`]: (state, data, params) => {
    	let state1 = clone(state)
    // loading=false;
    if(data.code == '0'){
        	state1.searchData = data.content.taskLists
    }
    return state1
  },  
  [`${types.GET_HOUSE_HOLDS_LIST}_SUCCESS`]: (state, data, params) => {
    	let state1 = clone(state)
    // loading=false;
    if(data.code == '0'){
        	state1.searchPsrsonData.data = data.content.householdList
        	state1.searchPsrsonData.pageSize = data.pageSize
        	state1.searchPsrsonData.totalPage = data.totalPage
        	state1.searchPsrsonData.currentPage = data.currentPage
        	state1.searchPsrsonData.totalRecord = data.totalRecord
    }
    return state1
  }
    
})